package com.dn.designpatterns.singleton;

/**
 * @program: designpatterns
 * @description: 双检锁/双重效验锁(DCL,即 double-checked locking)
 * @author: DN
 * @create: 2021-03-28 16:40
 **/
public class SingletonForDCL {

    private volatile static SingletonForDCL singleton;

    private SingletonForDCL() {}

    public static SingletonForDCL getInstance(){
        if (singleton == null) {
            synchronized (SingletonForDCL.class) {
                if (singleton == null) {
                    singleton = new SingletonForDCL();
                }
            }
        }
        return singleton;
    }
}

